package cn.com.code.design;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 抽象银行卡
 *
 * @author zhengpei
 * @date 2021/9/8
 */
public abstract class BankCard {

  private Logger logger = LoggerFactory.getLogger(BankCard.class);

  // 卡号
  private String cardNo;
  // 开卡时间
  private LocalDateTime cardDate;

  public BankCard(String cardNo, LocalDateTime cardDate) {
    this.cardDate = cardDate;
    this.cardDate = cardDate;
  }

  /**
   * 规则
   *
   * @return
   */
  abstract boolean rule();

  /**
   * 正向转账，加钱
   *
   * @return
   */
  public String positive(String orderId, BigDecimal amount) {
    // 入款成功，存款、还款
    logger.info("卡号{} 入款成功，单号：{} 金额：{}", cardNo, orderId, amount);
    return "0000";
  }

  /***
   * 逆向转账，扣钱
   * @param orderId
   * @param amount
   * @return
   */
  public String negative(String orderId, BigDecimal amount) {
    // 入款成功，存款、还款
    logger.info("卡号{} 出款成功，单号：{} 金额：{}", cardNo, orderId, amount);
    return "0000";
  }

  /**
   * 交易流水查询
   *
   * @return 交易流水
   */
  public List<String> tradeFlow() {
    logger.info("交易流水查询成功");
    List<String> tradeList = new ArrayList<String>();
    tradeList.add("100001,100.00");
    tradeList.add("100001,80.00");
    tradeList.add("100001,76.50");
    tradeList.add("100001,126.00");
    return tradeList;
  }

  public String getCardNo() {
    return cardNo;
  }

  public LocalDateTime getCardDate() {
    return cardDate;
  }

}
